package com.zw.pdm.module.file.service;

import com.zw.pdm.entity.production.FileSheet;
import com.zw.pdm.module.file.mapper.FileSignForMapper;
import com.zw.pdm.module.file.repository.FileSheetRepository;
import com.zw.pdm.module.system.service.LogService;
import com.zw.pdm.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author mayongfeng
 * @version 1.0.0
 * @ClassName FileSignForService.java
 * @Description TODO
 * @createTime 2020年12月17日 08:11:00
 */
@Service
@SuppressWarnings("all")
public class FileSignForService {

    @Autowired
    private FileSignForMapper fileSignForMapper;
    @Autowired
    private FileSheetRepository fileSheetRepository;
    @Autowired
    private LogService logService;

    /** 查询需要签收的存档列表*/
    public List<FileSheet> findFileSignFor(FileSheet fileSheet) {
       return fileSignForMapper.findFileSignFor(fileSheet);
    }

    /** 档案室签收存档*/
    public FileSheet signConfirm(Integer id) {
        FileSheet fileSheet = fileSheetRepository.getOne(id);
        /** 档案室签收状态 FileSignStatus 0=未签收，1=已签收，2=已拒收*/
        fileSheet.setFileSignStatus(1);
        fileSheet.setFileSigner(ShiroUtils.getUser().getName());
        fileSheet.setFileSignTime(new Date());
        fileSheet.setMayChange(1);
        logService.saveLog("签收存档", "签收存档ID：" + id);
        return fileSheetRepository.save(fileSheet);
    }

    /** 拒收存档*/
    public FileSheet signReject(FileSheet fileSheet) {
        FileSheet fileSheet1 = fileSheetRepository.getOne(fileSheet.getId());
        fileSheet1.setRejectReason(fileSheet.getRejectReason());
        fileSheet1.setDesignStatus(0);
        return  fileSheetRepository.saveAndFlush(fileSheet1);

    }

    public FileSheet modifyFile(FileSheet fileSheet) {
        FileSheet fileSheet1 = fileSheetRepository.getOne(fileSheet.getId());
        fileSheet1.setFileRemark(fileSheet.getFileRemark());
        return fileSheetRepository.save(fileSheet1);
    }
}


